package com.tester.yaa.exam002.computeThread;

/**
 * @Aduthor yinanan
 * @ClassName Resource
 * @Date 2022/12/11 20:00
 * @Description 资源信息类
 **/
public class Resource {

    //电脑信息
    private Coumputer coumputer;
    
    /** 
    * @Description: //产生电脑
    * @author: yinanan
    * @Param: []
    * @return: void  
    * @Date: 2022/12/11
    */ 
    public synchronized void make() throws Exception {
        if (this.coumputer != null) {
            //生成过了
            super.wait();
        }
        //线程休眠时间
        Thread.sleep(100);
        //初始化（生成）一台电脑
        this.coumputer = new Coumputer();
        System.out.println("[电脑工厂]" + this.coumputer);
        super.notifyAll();
    }

    /** 
    * @Description: //工人搬走电脑
    * @author: yinanan
    * @Param: []
    * @return: void  
    * @Date: 2022/12/11
    */ 
    public synchronized void get() throws Exception {
        if (this.coumputer == null) {    //还没生成
            super.wait();
        }
        Thread.sleep(10);
        System.out.println("[搬运工]" + this.coumputer);
        this.coumputer = null;
        super.notifyAll();
    }
}
